<template>
	<view class="cart-root">
		<com-nav-bar @clickLeft="back" left-icon="back" title="提交订单" :status-bar="true" :background-color="navBg" :border="false" :color="navCol"></com-nav-bar>
		<!-- 背景图，可自定义 -->
		<view class="cart-bg" :style="{background:'url('+bg_url+')'}"></view>
		<view class="mainContent">
			<view v-if="auth_pay" style="color:gray;font-size:26rpx;display:flex;flex-direction: column;align-items: center;background: rgba(255, 255, 255, 1);margin-bottom:30rpx;border-radius:10rpx;padding:20rpx 20rpx;">
				<text>授权支付</text>
				<view style="word-break: break-word;word-spacing: normal;">{{auth_token}}</view>
			</view>
			<view class="up">
				<view class="balance">
					<text>账户余额:</text>

					<view><text class="price">{{payData.balance}}</text>元</view>
				</view>
				<view class="balance">
					<text>恒信通余额:</text>
				
					<view><text class="price">{{payData.hxtBalance}}</text>元</view>
				</view>
				<view class="pay-content">
					<view class="pay-title">支付金额</view>
					<view class="pay-price" :style="{color:'#FF7104'}" v-if="payData"><text class="pay-icon">&yen;</text>{{payData.amount}}</view>
					<view class="numbering">订单编号：{{payData.orderNo}}</view>
				</view>
			</view>
			<view class="down" v-if="payData.amount && sign != 'meituan' && sign != 'easy_oil'">
				<view class="down-item" v-for="(item,index) in payData.supportPayTypes" :key="index">
					<view class="item-left">
						<image class="item-img" :src="img_url+'images/pay/'+item+'.png'" mode=""></image>
						<text v-if="item == 'wechat'">微信支付</text>
						<text v-if="item == 'bswechat'">微信在线支付</text>
						<text v-if="item == 'alipay'">支付宝支付</text>
						<text v-if="item == 'bsalipay'">支付宝在线支付</text>
						<text v-if="item == 'hjwechat'">微信在线支付</text>
						<text v-if="item == 'hjalipay'">支付宝在线支付</text>
						<text v-if="item == 'hjAgreementPay'">快捷支付</text>
						<text v-if="item == 'balance'">兰亭余额支付</text>
						<text v-if="item == 'offonline'">线下支付</text>
						<text v-if="item == 'localAlipay'">再团支付宝在线支付</text>
						<text v-if="item == 'localWechatpay'">再团微信在线支付</text>
						<text v-if="item == 'hxtOpenPay'">微信支付宝支付</text>
						<text v-if="item == 'hxtBalancePay'">恒信通余额支付</text>
					</view>
					<view class="item-right-box" @tap="switchIcon(index)">
						<view v-if="switchIndex == index" class="item-icon iconfont icon-dagou1" :style="{color:'#FF7104'}"></view>
						<view v-else class="item-right"></view>
					</view>
				</view>
			</view>
			<view class="down" v-else>
				<view class="down-item">
					<view class="item-left">
						<image class="item-img" :src="img_url+'images/pay/'+'balance'+'.png'" mode=""></image>
						<text>余额支付</text>
					</view>
					<view class="item-right-box">
						<view class="item-icon iconfont icon-dagou1" :style="{color:'#FF7104'}"></view>
					</view>
				</view>
			</view>

			<view class="confirmPay" @tap="confirmPay" :style="{background:'#FF7104'}">确认支付</view>
			
			<view v-if="payData.orderUser === payData.user_id" @click='toHelpPay' style="color: #FF7104;font-size: 10pt;text-align: right;margin-top: 40rpx;margin-right: 20rpx;">找朋友付</view>
		</view>
		<com-bottom-popup :show="popupShow">
			<view class="tui-popup-box" style="border-radius: 20rpx;">
				<scroll-view scroll-y class="tui-popup-scroll">
					<view class="tui-scrollview-box">
						<view style="text-align:center;">选择支付方式</view>
						<view class="uni-title uni-common-mt uni-common-pl">选择银行卡</view>
						<view class="uni-list">
							<radio-group @change="radioChange">
								<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in payData.hjBank" :key="item.sign_no">
									<view style="margin:10rpx 0;">
										<text>
											<radio :value="item.sign_no" color="green" :checked="index === current" />
										</text>
										<text> {{bankName[item.bank_code]? bankName[item.bank_code].name : item.bank_code }}({{endNumber(item.bank_card_no)}})</text>
									</view>
								</label>
							</radio-group>
						</view>
					</view>
				</scroll-view>
				<view class="tui-operation tui-operation-right tui-right-flex tui-popup-btn">
					<view class="confirmPay" :style="{background:'#FF7104'}" @tap="determine">确定</view>
				</view>
			</view>
		</com-bottom-popup>
		<com-modal :show="modal" @click="handleClick" @cancel="hide()" title="提示"
			content="您没有设置支付密码,是否需要跳转设置？"></com-modal>
		<com-payment-password ref="paymentPassword" :show="cashFlag" :value="paymentPwd" :digits="6" @submit="checkPwd"
			@cancel="togglePayment" @checkSafePwd="safePasswork"></com-payment-password>
		<svInterceptBack :show="true" content="你的订单还没有支付成功，请继续支付" />
	</view>
</template>

<script>
	// #ifdef H5
	var jweixin = require('jweixin-module');
	// #endif
	// #ifdef MP-WEIXIN || APP-PLUS
	import {
		setPay
	} from '@/config/utils.js'
	// #endif
	import {bankName} from "@/utils/util.js"
	import svInterceptBack from '@/components/sv-intercept-back/sv-intercept-back.vue';
	import { isWeChat } from '@/utils/util.js';
	export default {
		components: {
			svInterceptBack
		},
		data() {
			return {
				img_url: this.$api.img_url,
				showBool: false, // 固定定位状态栏占位
				is_index : '',	//是否为拼团支付的标记
				active_id : '',	//团id
				opacity: 0,
				token: '',
				queue_id: '',
				payData:{
					amount:0,
					balance:0,
					orderNo:'',
					orderToken:'',
					union_id:'',
					orderUser:0,
					user_id:'',
					hxtBalance:0,
				},
				switchIndex: 0,
				textColor:"#BC0100",
				bg_url:'',
				navBg:'',
				navCol:'',
				goods_id : '',
				auth_pay: false,
				auth_token: '',
				order_id: '',
				sign: '',
				popupShow:false,
				sign_no:'',
				current: 0,
				bankName: bankName(),
				is_transaction_password:'',
				modal:false,
				cashFlag:false,
				paymentPwd:'',
				payType:'1',//显示当前的支付方式
				isWeChat:isWeChat(),
				requestFlag:true
			}
		},
		computed: {
			endNumber() {
				return (cardCode) => {
					let length = cardCode.length;
					return cardCode.substr(length - 4, length);
				} 
			}
		},
		onLoad(options) {
			//pay_sence : 应付复杂的支付场景。
			//order: 商城订单支付; supply_chain: 进货系统; use_deduct: 积分红包抵扣订单; mch_order 入驻商家的订单;
			//mch_store: 商家爆品订单; baiguoyuan: 百果园订单
			this.pay_sence = options.pay_sence ? options.pay_sence : 'order';
			this.order_id = options.orderId ? options.orderId : '';
			
			if(options.goods_id){
				this.goods_id = options.goods_id;
			}
			
			// if(options.payType){
			// 	this.payType = options.payType;
			// }
			
			let that = this, timer = setInterval(function(){
				if(uni.getStorageSync('mall_config')){
					that.textColor = that.globalSet('textCol');
					that.bg_url    = that.globalSet('imgUrl');
					that.navBg     = that.globalSet('navBg');
					that.navCol    = that.globalSet('navCol');
					clearInterval(timer);
				}
			}, 500);
			
	
			this.sign = options.sign || '';
			this.token = options.token;
			this.queue_id = options.queue_id;	

			// 加多一个是否为拼团支付的标记
			if(options.is_index){
				this.is_index = 1;
				this.active_id = options.active_id;
			}


		},
		onShow() {
			// 拿到支付信息
			if(!uni.getStorageSync("auth_pay")){
				
				// this.pay_sence == 'mch_store' 商家添加的平台爆品商品
				if( this.pay_sence == 'order' || this.pay_sence == 'use_deduct' || this.pay_sence == 'mch_order' || this.pay_sence == 'mch_store'){
					this.getPayData(this.order_id);
				}else{
					uni.showToast({title:'当前订单暂不支持',icon:'none'});
				}
				
				// if(this.pay_sence == 'supply_chain'){
				// 	this.supplyChainData(this.order_id);
				// }
				
			}else{
				this.auth_pay = true;
				this.auth_token = uni.getStorageSync("auth_token");
			}
			// this.initSetting()
			let userInfo = uni.getStorageSync('userInfo');
			userInfo = JSON.parse(userInfo);
			this.is_transaction_password = userInfo.is_transaction_password;
		},
		methods: {
			
			togglePayment() {
				this.cashFlag = false;
			},
			safePasswork(e) {
				let that = this;
				uni.showLoading({
					title: '校验安全密码中'
				});
				this.$http.request({
					url: this.$api.hj.transactionPassword,
					method: 'POST',
					data: {transaction_password:e.passwork},
					showLoading: true
				}).then(res => {
					this.$refs.paymentPassword.modalFun('hide');
					if (res.code == 0) {
						that.$http.request({
							url: that.$api.moreShop.hjAgreementPay,
							showLoading: true,
							method: 'post',
							data: {
								union_id: that.payData.union_id,
								sign_no:that.sign_no
							}
						}).then(res=>{
							if(res.code==0){
								that.$http.toast('支付成功!');
								if(that.payData.is_send==1){
									setTimeout(() => {
										// #ifdef APP-PLUS
											uni.navigateTo({
												url: '/pages/order/beused/beused'
											})
										// #endif
										// #ifdef H5||MP-WEIXIN
											uni.redirectTo({
												url: '/pages/order/beused/beused'
											})
										// #endif
									},700)
								}else{
									setTimeout(() => {
										
										// #ifdef APP-PLUS
											uni.navigateTo({
												url: '/pages/order/list?status=1'
											})
										// #endif
										
										// #ifdef H5||MP-WEIXIN
											uni.redirectTo({
												url: '/pages/order/list?status=1'
											})
										// #endif
									},500)
								}
								return;
							}else{
								that.$http.toast(res.msg)
							}
							
						})
					} else {
						this.$http.toast(res.msg);
					}
				});
			},
			checkPwd(e){
				console.log({e});
			},
			initSetting() {
				this.$http
					.request({
						url: this.$api.plugin.extensions.integral_cash.setting
					})
					.then(res => {
						if (res.code == 0) {
							this.is_transaction_password = res.data.user_info.is_transaction_password;
						}
					});
			},
			hide(){
				this.modal = false
			},
			handleClick(e) {
				let index = e.index;
				if (index === 0) {
					this.modal = false;
				} else {
					uni.navigateTo({
						url: '/pages/user/payment/password'
					})
				}
				this.hide();
			},
			radioChange: function(evt) {
				for (let i = 0; i < this.payData.hjBank.length; i++) {
					if (this.payData.hjBank[i].sign_no === evt.detail.value) {
						this.current = i;
						break;
					}
				}
			},
			determine(){
				if(this.payData.hjBank.length>0){
					this.sign_no = this.payData.hjBank[this.current].sign_no;
				}
				
				this.popupShow = false;
			},
			hidePopup() { //关闭弹窗
				this.popupShow = false;
			},
			back() {
				this.navBack();
			},
			// 获取支付信息
			getPayData(id) {
				//每次请求增加时间戳，避免浏览器从缓存加载接口数据
				let time = new Date().getTime();
				this.$http.request({
					url: this.$api.order.toPay,
					showLoading: true,
					data: {
						token: this.token || '',
						queue_id: this.queue_id || '',
						id,time
					}
				}).then((res) => {
					if (res.code == 0) {
						this.payData = res.data;
						this.is_transaction_password = res.data.is_pay_password
						// this.payData.supportPayTypes = ['balance','hjwechat','hjalipay','hjAgreementPay']
						for(let i=0; i < this.payData.supportPayTypes.length; i++){
							// if(this.payData.supportPayTypes[i] == 'wechat'){
							//默认使用收银台支付
							if(this.payData.supportPayTypes[i] == 'hxtOpenPay'){
								this.switchIndex = i;
								break;
							}
						}
					}else{
						this.$http.toast(res.msg)
					}
				})
			},
			// 请求支付接口
			async confirmPay(){
				let that = this;
				if(that.payData.amount==0){
					let res = await that.$http.request({
						url: that.$api.moreShop.balancepay,
						showLoading: true,
						method: 'post',
						data: {
							union_id: that.payData.union_id,
						}
					});
					if(res.code != 0){
						that.$http.toast(res.msg);return;
					}
					that.$http.toast('支付成功!');
					if(that.sign == "meituan"){
						that.checkMeituanOrderStatus();return;
					}else if(that.sign == "easy_oil"){
						that.checkEasyOilOrderStatus();return;
					}
					
					if(that.payData.is_send==1){
						setTimeout(() => {
							// #ifdef APP-PLUS
								uni.navigateTo({
									url: '/pages/order/beused/beused'
								})
							// #endif
							// #ifdef H5||MP-WEIXIN
								uni.redirectTo({
									url: '/pages/order/beused/beused'
								})
							// #endif
						},500)
					}else{
						setTimeout(() => {
							// #ifdef APP-PLUS
								uni.navigateTo({
									url: '/pages/order/list?status=1'
								})
							// #endif
							// #ifdef H5||MP-WEIXIN
								uni.redirectTo({
									url: '/pages/order/list?status=1'
								})
							// #endif
						},500)
					}
					
				}else{
					if(that.payData.supportPayTypes[that.switchIndex]=='alipay'){
							that.$http.request({
								url: that.$api.moreShop.alipay,
								showLoading: true,
								method: 'post',
								data: {
									union_id: that.payData.union_id,
								}
							}).then(res=>{
								if(res.code==0){
									// #ifdef APP-PLUS
											uni.navigateTo({
												url: '/pages/order/alipayWeb?url=' + res.data.codeUrl
											})
									// #endif
									 // #ifdef H5
									let url=res.data.codeUrl
									location.href=url
									// #endif
								}else{
									that.$http.toast(res.msg)
								}
							})
					}
					if(that.payData.supportPayTypes[that.switchIndex]=='wechat'){
						// #ifdef H5
								that.$http.request({
									url: that.$api.moreShop.wechatpay,
									showLoading: true,
									method: 'post',
									data: {
										union_id: that.payData.union_id,
										stands_mall_id:JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id!=null?JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id:5,
										wx_type:'wechat'//公众号：wechat  小程序：mp-wx
									}
								}).then(res=>{
									if(res.code==0){
										if(that.payData.is_send==1){
											that.$wechatSdk.pay(res.data,'/pages/order/beused/beused');
										}else{
											that.$wechatSdk.pay(res.data,'/pages/order/list?status=1');
										}
									}else{
										that.$http.toast(res.msg);	
									}
								})
						// #endif
						// #ifdef MP-WEIXIN || APP-PLUS
								that.$http.request({
									url: that.$api.moreShop.wechatpay,
									showLoading: true,
									method: 'post',
									data: {
										union_id: that.payData.union_id,
										stands_mall_id:JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id!=null?JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id:5,
										wx_type:'mp-wx'//公众号：wechat  小程序：mp-wx
									}
								}).then(res=>{
									if(res.code==0){
										setPay(res.data, (result) => {
											let _url = '/pages/order/list?status=1'
											if (result.success) {
												that.$http.toast("支付成功")
											} else {
												that.$http.toast("未支付")
												_url = '/pages/order/list?status=0'
											}
											if(that.payData.is_send==1){
												setTimeout(() => {
													// #ifdef APP-PLUS
														uni.navigateTo({
															url: '/pages/order/beused/beused'
														})
													// #endif
													// #ifdef H5||MP-WEIXIN
														uni.redirectTo({
															url: '/pages/order/beused/beused'
														})
													// #endif
												},500)
											}else{
												setTimeout(() => {
													// #ifdef APP-PLUS
														uni.navigateTo({
															url: _url
														})
													// #endif
													// #ifdef H5||MP-WEIXIN
														uni.redirectTo({
															url: _url
														})
													// #endif
												},1000)
											}																
										});
									}else{
										that.$http.toast(res.msg);	
									}
								})
						// #endif			
					}
					if(that.payData.supportPayTypes[that.switchIndex]=='bswechat'){
						// #ifdef H5
								that.$http.request({
									url: that.$api.moreShop.bswechatpay,
									showLoading: true,
									method: 'post',
									data: {
										union_id: that.payData.union_id,
										stands_mall_id:JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id!=null?JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id:5,
										wx_type:'wechat'//公众号：wechat  小程序：mp-wx
									}
								}).then(res=>{
									if(res.code==0){
										if(that.payData.is_send==1){
											that.$wechatSdk.pay(res.data,'/pages/order/beused/beused');
										}else{
											that.$wechatSdk.pay(res.data,'/pages/order/list?status=1');
										}
									}else{
										that.$http.toast(res.msg);	
									}
								})
						// #endif
						// #ifdef MP-WEIXIN || APP-PLUS
								that.$http.request({
									url: that.$api.moreShop.bswechatpay,
									showLoading: true,
									method: 'post',
									data: {
										union_id: that.payData.union_id,
										stands_mall_id:JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id!=null?JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id:5,
										wx_type:'mp-wx'//公众号：wechat  小程序：mp-wx
									}
								}).then(res=>{
									if(res.code==0){
										setPay(res.data, (result) => {
											let _url = '/pages/order/list?status=1'
											if (result.success) {
												that.$http.toast("支付成功")
											} else {
												that.$http.toast("未支付")
												_url = '/pages/order/list?status=0'
											}
											if(that.payData.is_send==1){
												setTimeout(() => {
													// #ifdef APP-PLUS
														uni.navigateTo({
															url: '/pages/order/beused/beused'
														})
													// #endif
													// #ifdef H5||MP-WEIXIN
														uni.redirectTo({
															url: '/pages/order/beused/beused'
														})
													// #endif
												},500)
											}else{
												setTimeout(() => {
													// #ifdef APP-PLUS
														uni.navigateTo({
															url: _url
														})
													// #endif
													// #ifdef H5||MP-WEIXIN
														uni.redirectTo({
															url: _url
														})
													// #endif
												},1000)
											}																
										});
									}else{
										that.$http.toast(res.msg);	
									}
								})
						// #endif			
					}
					if(that.payData.supportPayTypes[that.switchIndex]=='hjwechat'){
						// #ifdef H5
								that.$http.request({
									url: that.$api.moreShop.hjwechatpay,
									showLoading: true,
									method: 'post',
									data: {
										union_id: that.payData.union_id,
										stands_mall_id:JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id!=null?JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id:5,
										wx_type:'wechat'//公众号：wechat  小程序：mp-wx
									}
								}).then(res=>{
									if(res.code==0){
										if(that.payData.is_send==1){
											that.$wechatSdk.pay(res.data,'/pages/order/beused/beused');
										}else{
											that.$wechatSdk.pay(res.data,'/pages/order/list?status=1');
										}
									}else{
										that.$http.toast(res.msg);	
									}
								})
						// #endif
						// #ifdef MP-WEIXIN || APP-PLUS
								that.$http.request({
									url: that.$api.moreShop.bswechatpay,
									showLoading: true,
									method: 'post',
									data: {
										union_id: that.payData.union_id,
										stands_mall_id:JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id!=null?JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id:5,
										wx_type:'mp-wx'//公众号：wechat  小程序：mp-wx
									}
								}).then(res=>{
									if(res.code==0){
										setPay(res.data, (result) => {
											let _url = '/pages/order/list?status=1'
											if (result.success) {
												that.$http.toast("支付成功")
											} else {
												that.$http.toast("未支付")
												_url = '/pages/order/list?status=0'
											}
											if(that.payData.is_send==1){
												setTimeout(() => {
													// #ifdef APP-PLUS
														uni.navigateTo({
															url: '/pages/order/beused/beused'
														})
													// #endif
													// #ifdef H5||MP-WEIXIN
														uni.redirectTo({
															url: '/pages/order/beused/beused'
														})
													// #endif
												},500)
											}else{
												setTimeout(() => {
													// #ifdef APP-PLUS
														uni.navigateTo({
															url: _url
														})
													// #endif
													// #ifdef H5||MP-WEIXIN
														uni.redirectTo({
															url: _url
														})
													// #endif
												},1000)
											}																
										});
									}else{
										that.$http.toast(res.msg);	
									}
								})
						// #endif			
					}
					if(that.payData.supportPayTypes[that.switchIndex]=='balance'){
						that.$http.request({
							url: that.$api.moreShop.balancepay,
							showLoading: true,
							method: 'post',
							data: {
								union_id: that.payData.union_id,
							}
						}).then(res=>{
							if(res.code==0){
								that.$http.toast('支付成功!');
								
								if(that.sign == "meituan"){
									that.checkMeituanOrderStatus();
									return;
								}else if(that.sign == "easy_oil"){
									that.checkEasyOilOrderStatus();
									retrun;
								}
								
								if(that.payData.is_send==1){
									setTimeout(() => {
										// #ifdef APP-PLUS
											uni.navigateTo({
												url: '/pages/order/beused/beused'
											})
										// #endif
										// #ifdef H5||MP-WEIXIN
											uni.redirectTo({
												url: '/pages/order/beused/beused'
											})
										// #endif
									},500)
								}else{
									setTimeout(() => {
										
										// #ifdef APP-PLUS
											uni.navigateTo({
												url: '/pages/order/list?status=1'
											})
										// #endif
										
										// #ifdef H5||MP-WEIXIN
											uni.redirectTo({
												url: '/pages/order/list?status=1'
											})
										// #endif
									},500)
								}
								return;
							}else{
								that.$http.toast(res.msg)
							}
						})
					}
					if(that.payData.supportPayTypes[that.switchIndex]=='offonline'){
						that.$http.request({
							url: that.$api.moreShop.offonline,
							showLoading: true,
							method: 'post',
							data: {
								union_id: that.payData.union_id,
							}
						}).then(res=>{
							if(res.code==0){
								that.$http.toast('订单创建成功!');
								
								
								if(that.payData.is_send==1){
									setTimeout(() => {
										// #ifdef APP-PLUS
											uni.navigateTo({
												url: '/pages/order/beused/beused'
											})
										// #endif
										// #ifdef H5||MP-WEIXIN
											uni.redirectTo({
												url: '/pages/order/beused/beused'
											})
										// #endif
									},500)
								}else{
									setTimeout(() => {
										
										// #ifdef APP-PLUS
											uni.navigateTo({
												url: '/pages/order/list?status=0'
											})
										// #endif
										
										// #ifdef H5||MP-WEIXIN
											uni.redirectTo({
												url: '/pages/order/list?status=0'
											})
										// #endif
									},500)
								}
								return;
							}else{
								that.$http.toast(res.msg)
							}
						})
					}
					if(that.payData.supportPayTypes[that.switchIndex]=='bsalipay'){
							that.$http.request({
								url: that.$api.moreShop.bsalipay,
								showLoading: true,
								method: 'post',
								data: {
									union_id: that.payData.union_id,
								}
							}).then(res=>{
								if(res.code==0){
									// #ifdef APP-PLUS
									uni.navigateTo({
										url: '/pages/order/alipayWeb?url=' + res.data.qr_code
									})
									// #endif
									// #ifdef H5
									if(this.$http.getPlatform() == 'wechat'){
										uni.navigateTo({
											url: '/pages/order/bsalipayWeb?url=' + res.data.qr_code
										})
									}else{
										let url=res.data.qr_code
										location.href=url
									}
									// #endif
								}else{
									that.$http.toast(res.msg)
								}
							})
					}
					if(that.payData.supportPayTypes[that.switchIndex]=='hjalipay'){
							that.$http.request({
								url: that.$api.moreShop.hjalipay,
								showLoading: true,
								method: 'post',
								data: {
									union_id: that.payData.union_id,
								}
							}).then(res=>{
								if(res.code==0){
									// #ifdef APP-PLUS
									uni.navigateTo({
										url: '/pages/order/alipayWeb?url=' + res.data.rc_Result
									})
									// #endif
									// #ifdef H5
									if(this.$http.getPlatform() == 'wechat'){
										uni.navigateTo({
											url: '/pages/order/bsalipayWeb?url=' + res.data.rc_Result
										})
									}else{
										let url=res.data.rc_Result
										location.href=url
									}
									// #endif
								}else{
									that.$http.toast(res.msg)
								}
							})
					}
					if(that.payData.supportPayTypes[that.switchIndex]=='hjAgreementPay'){
						if(!(that.payData.hjBank.length>0)){
							uni.navigateTo({
								url: '/pages/user/bindBank/addBank'
							})
							return
						}
						if(!that.sign_no){
							that.$http.toast('请点击快捷支付，选择银行卡')
							return
						}
						// 没有设置支付密码
						if (!that.is_transaction_password) {
							that.modal = true;
							return;
						}
						that.cashFlag = true;
						that.$refs.paymentPassword.modalFun('show');
						return
						// that.$http.request({
						// 	url: that.$api.moreShop.hjAgreementPay,
						// 	showLoading: true,
						// 	method: 'post',
						// 	data: {
						// 		union_id: that.payData.union_id,
						// 		sign_no:that.sign_no
						// 	}
						// }).then(res=>{
						// 	if(res.code==0){
						// 		that.$http.toast('支付成功!');
						// 		if(that.payData.is_send==1){
						// 			setTimeout(() => {
						// 				// #ifdef APP-PLUS
						// 					uni.navigateTo({
						// 						url: '/pages/order/beused/beused'
						// 					})
						// 				// #endif
						// 				// #ifdef H5||MP-WEIXIN
						// 					uni.redirectTo({
						// 						url: '/pages/order/beused/beused'
						// 					})
						// 				// #endif
						// 			},700)
						// 		}else{
						// 			setTimeout(() => {
										
						// 				// #ifdef APP-PLUS
						// 					uni.navigateTo({
						// 						url: '/pages/order/list?status=1'
						// 					})
						// 				// #endif
										
						// 				// #ifdef H5||MP-WEIXIN
						// 					uni.redirectTo({
						// 						url: '/pages/order/list?status=1'
						// 					})
						// 				// #endif
						// 			},500)
						// 		}
						// 		return;
						// 	}else{
						// 		that.$http.toast(res.msg)
						// 	}
							
						// })
					}
					
					if(that.payData.supportPayTypes[that.switchIndex]=='hxtOpenPay'){
						if(!that.requestFlag){
							return ;
						}
						that.requestFlag = false;
						let res = await that.$http.request({
							url: that.$api.hxt.hxtOpenPay,
							showLoading: true,
							method: 'post',
							data: {union_id: that.payData.union_id}
						});
						that.requestFlag = true;
						if(res.code != 0){
							that.$http.toast(res.msg);return;
						}
						// uni.navigateTo({
						//   url: res.data.code_url // 直接跳转到外部链接
						// });
						window.location.href = res.data.code_url;
						// console.log('hxtOpenPay',res)
					}
					
					if(that.payData.supportPayTypes[that.switchIndex]=='hxtBalancePay'){
						if(!that.requestFlag){
							return ;
						}
						that.requestFlag = false;
						let res = await that.$http.request({
							url: that.$api.hxt.hxtBalancePay,
							showLoading: true,
							method: 'post',
							data: {union_id: that.payData.union_id}
						});
						if(res.code != 0){
							that.requestFlag = true;
							that.$http.toast(res.msg);return;
						}
						that.$http.toast('支付成功');
						setTimeout(() => {
							that.requestFlag = true;
							uni.navigateTo({
								url: '/pages/order/list?status=1'
							})
						},1000)
					}
					
					if(that.payData.supportPayTypes[that.switchIndex]=='localAlipay'){
						that.$http.request({
							url: that.$api.moreShop.localAlipay,
							showLoading: true,
							method: 'post',
							data: {
								union_id: that.payData.union_id,
							}
						}).then(res=>{
							if(res.code==0){
								// #ifdef APP-PLUS
									uni.navigateTo({
										url: '/pages/order/alipayWeb?url=' + res.data.qr_code
									})
								// #endif
								// #ifdef H5
								if(this.$http.getPlatform() == 'wechat'){
									uni.navigateTo({
										url: '/pages/order/bsalipayWeb?url=' + res.data.qr_code
									})
								}else{
									let url=res.data.qr_code
									location.href=url
								}
								// #endif
							}else{
								that.$http.toast(res.msg)
							}
						})
					}		
					if(that.payData.supportPayTypes[that.switchIndex]=='localWechatpay'){
						// #ifdef H5
								that.$http.request({
									url: that.$api.moreShop.localWechatpay,
									showLoading: true,
									method: 'post',
									data: {
										union_id: that.payData.union_id,
										stands_mall_id:JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id!=null?JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id:5,
										wx_type:'wechat'//公众号：wechat  小程序：mp-wx
									}
								}).then(res=>{
									if(res.code==0){
										if(that.payData.is_send==1){
											that.$wechatSdk.pay(res.data,'/pages/order/beused/beused');
										}else{
											that.$wechatSdk.pay(res.data,'/pages/order/list?status=1');
										}
									}else{
										that.$http.toast(res.msg);	
									}
								})
						// #endif
						
						// #ifdef MP-WEIXIN || APP-PLUS
								that.$http.request({
									url: that.$api.moreShop.localWechatpay,
									showLoading: true,
									method: 'post',
									data: {
										union_id: that.payData.union_id,
										stands_mall_id:JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id!=null?JSON.parse(uni.getStorageSync('mall_config')).stands_mall_id:5,
										wx_type:'mp-wx'//公众号：wechat  小程序：mp-wx
									}
								}).then(res=>{
									if(res.code==0){
										setPay(res.data, (result) => {
											let _url = '/pages/order/list?status=1'
											if (result.success) {
												that.$http.toast("支付成功")
											} else {
												that.$http.toast("未支付")
												_url = '/pages/order/list?status=0'
											}
											if(that.payData.is_send==1){
												setTimeout(() => {
													// #ifdef APP-PLUS
														uni.navigateTo({
															url: '/pages/order/beused/beused'
														})
													// #endif
													// #ifdef H5||MP-WEIXIN
														uni.redirectTo({
															url: '/pages/order/beused/beused'
														})
													// #endif
												},500)
											}else{
												setTimeout(() => {
													// #ifdef APP-PLUS
														uni.navigateTo({
															url: _url
														})
													// #endif
													// #ifdef H5||MP-WEIXIN
														uni.redirectTo({
															url: _url
														})
													// #endif
												},1000)
											}																
										});
									}else{
										that.$http.toast(res.msg);	
									}
								})
						// #endif
					}

				}
			},	
			checkMeituanOrderStatus(){
				let order_no = this.payData['orderNo'];
				uni.redirectTo({
					url: `/meituan/checkOrderStatus?order_no=${order_no}`
				});
			},
			checkEasyOilOrderStatus(){
				let order_no = this.payData['orderNo'];
				uni.redirectTo({
					url: `/easy_oil/checkOrderStatus?order_no=${order_no}`
				});
				// this.$http
				// 	.request({
				// 		url: this.$api.easyOil.checkStatus,
				// 		method: 'POST',
				// 		data:{
				// 			order_no:order_no
				// 		}
				// 	})
				// 	.then(res => {
				// 		console.log({res});
				// });	
			},
			switchIcon(index) {
				this.switchIndex = index;
				if(this.payData.supportPayTypes[this.switchIndex]=='hjAgreementPay'){
					if(!(this.payData.hjBank.length>0)){
						uni.navigateTo({
							url: '/pages/user/bindBank/addBank'
						})
					}else{
						this.popupShow = true;
					}
					
				}
				
			},
			
			//找朋友付款
			async toHelpPay(){
				let self = this;
				let token = self.payData.orderToken;
				
				uni.showModal({
					title: '温馨提示',
					content: '您确定要生成亲友代付的付款链接吗？生成后您仍可以前往订单列表自己付款。',
					confirmText:'确定',
					cancelText:'我再想想',
					success: async function (res) {
						if (res.confirm) {
							let response = await self.$http.request({
								url: self.$api.order.helpOrderCreate,
								showLoading: true,
								method: 'post',
								data: {token}
							});
							console.log(123,response)
							if(response.code != 0){
								uni.showToast({icon:'none',title:response.msg});
								return ;
							}
							uni.navigateTo({
								url: '/pages/order/helpPay?type=1&token='+token
							})
						}
					}
				});

			},
			
			
			supplyChainData(id){
				this.loading = true;
				this.$http.request({
					url: this.$api.purchasing_system.onlinePay,
					method: 'POST',
					data: {id},
					showLoading:true
				}).then(res => {
					this.loading = false;
					if(res.code == 0){
						this.payData = res.data;
						this.$set(this,'payData',res.data);
						
						if(this.isWeChat){
							this.payData.supportPayTypes = {
								1:'bswechat',
								2:'bsalipay',
								3:'offonline'
							}
						}else{
							this.payData.supportPayTypes = {
								2:'bsalipay',
								3:'offonline'
							}
						}
						this.$forceUpdate();
					}else{
						uni.showToast({
						    title:res.msg,
						    duration: 3000,
							icon:'none'
						});
					}		
				})
			}
		},
	}
</script>

<style scoped>
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.status_bar2 {
		height: var(--status-bar-height);
		width: 100%;
		position: fixed;
		top: 0;
		z-index: 99;
	}

	body,
	page {
		background-color: $uni-bg-color-grey;
	}

	.cart-root {
		position: relative;
		z-index: 1;
	}

	.cart-bg {
		position: absolute;
		width: 100%;
		background-size: cover;
		height: 320rpx;
	}

	.cart-bg-img {
		width: 100%;
	}

	.cart-title {
		padding: 40rpx 0 0rpx;
		color: #FFFFFF;
		font-size: 14pt;
		letter-spacing: 4rpx;
		text-align: center;
		position: relative;
		margin-bottom: 40rpx;
	}

	.back {
		position: absolute;
		top: 40rpx;
		left: 30rpx;
		font-size: 40rpx;
	}

	.mainContent {
		z-index: 999;
		position: relative;
		width: 690rpx;
		margin: 118rpx auto 0;
	}

	.up {
		background: #FFFFFF;
		border-radius: 15rpx;
		margin-bottom: 30rpx;
	}

	.balance {
		display: flex;
		justify-content: space-between;
		padding: 30rpx 23rpx;
		font-size: 10pt;
		color: #000000;
		border-bottom: 2rpx solid #F2F2F2;
	}

	.price {
		font-size: 13pt;
		margin-right: 10rpx;
	}

	.pay-content {
		padding: 43rpx 0;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.pay-title {
		font-size: 9pt;
		font-weight: 600;
		margin-bottom: 20rpx;
		color: #000000;
	}

	.pay-icon {
		font-size: 12pt;
		margin-right: 20rpx;
		font-weight: 500;
	}

	.pay-price {
		color: #BC0100;
		font-size: 16pt;
		font-weight: 600;
		margin-bottom: 20rpx;
	}

	.numbering {
		font-size: 10pt;
		color: #000000;
	}

	.down {
		background: #FFFFFF;
		border-radius: 15rpx;
		padding: 40rpx 20rpx;
	}

	.down-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 40rpx;
	}

	.down .down-item:last-child {
		margin-bottom: 0rpx;
	}

	.item-left {
		display: flex;
		align-items: center;
		color: #000000;
		font-size: 10pt;
	}

	.item-img {
		width: 40rpx;
		height: 40rpx;
		margin-right: 30rpx;
	}

	.item-right-box {
		width: 38rpx;
		height: 38rpx;
		position: relative;
	}

	.item-right {
		width: 38rpx;
		height: 38rpx;
		border-radius: 50%;
		border: 2rpx solid #8B8B8B;
		position: absolute;
	}

	.item-icon {
		font-size: 38rpx;
		position: absolute;
		top: 0rpx;
		left: 0rpx;
		line-height: 40rpx;
		color: #BC0100;
	}

	.confirmPay {
		color: #FFFFFF;
		background: #bc0100;
		padding: 26rpx 0;
		text-align: center;
		border-radius: 80rpx;
		font-size: 10pt;
		letter-spacing: 4rpx;
		margin-top: 80rpx;
	}
/*底部选择弹层*/
	

	.tui-popup-box {
		position: relative;
		padding: 30rpx 0 100rpx 0;
	}

	.tui-popup-btn {
		width: 100%;
		position: absolute;
		left: 0;
		bottom: 0;
	}

	.tui-icon-close {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
	}

	.tui-product-box {
		display: flex;
		align-items: center;
		font-size: 9pt;
		padding-bottom: 30rpx;
	}

	.tui-popup-img {
		height: 200rpx;
		width: 200rpx;
		border-radius: 24rpx;
		display: block;
	}

	.tui-popup-price {
		padding-left: 20rpx;
		padding-bottom: 8rpx;
		flex: 1;
	}

	.tui-amount {
		color: #ff201f;
		font-size: 14pt;
	}

	.tui-number {
		font-size: 9pt;
		line-height: 28rpx;
		padding-top: 12rpx;
		color: #999;
	}

	.tui-popup-scroll {
		height: 1300rpx;
		font-size: 10pt;
	}

	.tui-scrollview-box {
		padding: 0 30rpx 60rpx 30rpx;
		box-sizing: border-box;
	}

	.tui-attr-title {
		padding: 10rpx 0;
		color: #333;
	}

	.tui-attr-box {
		font-size: 0;
		padding: 20rpx 0;
	}

	.tui-attr-item {
		max-width: 100%;
		min-width: 200rpx;
		height: 64rpx;
		display: -webkit-inline-flex;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		background: #f7f7f7;
		padding: 0 26rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		font-size: 9.5pt;
	}

	.tui-attr-active {
		font-weight: bold;
		position: relative;
		border-radius: 10rpx;
	}


	.tui-number-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 0 30rpx 0;
		box-sizing: border-box;
	}

	/*底部选择弹层*/
</style>
